//
//  TTMusicDiscoveryPageForthCollectionViewCell.m
//  TTMusic
//
//  Created by chenpengyu on 16/3/31.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "TTMusicDiscoveryPageForthCollectionViewCell.h"

@implementation TTMusicDiscoveryPageForthCollectionViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.picImageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 115, 115)];
        self.titleLabel=[[TTMusicBaseLabel alloc] initWithFrame:CGRectMake(_picImageView.frame.origin.x, 125, _picImageView.bounds.size.width + 10, 50)];
//        _titleLabel.numberOfLines = 2;
        _tingNumLabel.font = [UIFont systemFontOfSize:16];
//        _titleLabel.textColor = [UIColor blackColor];
        self.earPhoneImageView=[[UIImageView alloc] initWithFrame:CGRectMake(75, 15, 15, 15)];
        self.tingNumLabel=[[TTMusicBaseLabel alloc] initWithFrame:CGRectMake(_earPhoneImageView.bounds.size.width + _earPhoneImageView.frame.origin.x + 5, _earPhoneImageView.frame.origin.y, 40, _earPhoneImageView.bounds.size.height)];
        _tingNumLabel.font = [UIFont systemFontOfSize:14];
//        _tingNumLabel.textColor = [UIColor whiteColor];
        self.authouLabel=[[TTMusicBaseLabel alloc] initWithFrame:CGRectMake(15, 100, 65, 15)];
        _authouLabel.font = [UIFont systemFontOfSize:15];
//        self.authouLabel.textColor = [UIColor whiteColor];
        self.earPhoneImageView.image=[UIImage imageNamed:@"earPhone"];
        [self updateFrame:_picImageView];
        [self updateFrame:_titleLabel];
        [self updateFrame:_tingNumLabel];
        [self updateFrame:_authouLabel];
        [self updateFrame:_earPhoneImageView];

        [self.contentView addSubview:_picImageView];
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_tingNumLabel];
        [self.contentView addSubview:_authouLabel];
        [self.contentView addSubview:_earPhoneImageView];
    }
    return self;
}
- (void)updateFrame:(UIView *)view{
    
    CGRect rect = view.frame;
    view.frame = CGRectMake(rect.origin.x * FitWidth, rect.origin.y * FitWidth, rect.size.width * FitWidth, rect.size.height * FitWidth);
}
- (void)setDataModel:(CPYDiscoveryPageDataModel *)dataModel {
    _dataModel = dataModel;
}
- (void)setDataDetailModel:(CPYDiscoveryPageDataDetailModel *)dataDetailModel {
    _dataDetailModel = dataDetailModel;
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:dataDetailModel.picUrl]];
    if ([dataDetailModel.author isEqualToString:dataDetailModel.desc]) {
        _titleLabel.numberOfLines = 1;
    }else if(dataDetailModel.status.intValue == 1){
        _titleLabel.numberOfLines = 2;
    }else {
        _titleLabel.numberOfLines = 2;
    }
    _titleLabel.text = dataDetailModel.name;
    if (dataDetailModel.listenCount.intValue/10000 == 0) {
        _earPhoneImageView.hidden = _tingNumLabel.hidden = YES;
    }else {
        _earPhoneImageView.hidden = NO;
        _tingNumLabel.text=[NSString stringWithFormat:@"%d万",_dataDetailModel.listenCount.intValue/10000];
    }
    _authouLabel.text = dataDetailModel.author;
    _earPhoneImageView.image = [UIImage imageNamed:@"erji"];
}
@end
